home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5440 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mail2news.demon.co.uk!ues5.cern.ch
  2. From: Dan Pop <danpop@ues5.cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Question about sscanf
  5. Date: Fri, 9 Feb 1996 21:33:24 +0100
  6. Message-ID: <9602092033.AA07743@ues5.cern.ch>
  7. References: <4fe1oq$kuf@zippy.cais.net>
  8. X-NNTP-Posting-Host: ues5.cern.ch
  9. X-Newsreader: NN version 6.5.0 #7 (NOV)
  10. X-Mail2News-Path: mail1.cern.ch!ues5.cern.ch
  11.  
  12. In <4fe1oq$kuf@zippy.cais.net> usaid@cais.cais.com (USAID) writes:
  13.  
  14. >Here is a fragment of code that I'm having a problem with.  The program 
  15. >is bombing on the line containing the call to sscanf.  It assigns to the 
  16. >first variable fine, but blows up on the second one.  I have no idea 
  17. >what's wrong.
  18. >
  19. >int formatFile(void)
  20. >{
  21. >   int i;
  22. >   char line[MAX_LINE_LEN + 1]; 
  23. >   char *name; 
  24. >   char *value; 
  25. >   char *val[MAXREGIONS]; 
  26. >   char *delimiter = ", "; 
  27. >   FILE *ifp, *ofp; 
  28. >
  29. >   /* open input and output files */
  30. >   ifp = fopen("/opt/basis/tcs/formdata/test.txt", "r"); 
  31. >   ofp = fopen("/opt/basis/tcs/formdata/import.txt", "w"); 
  32. >   if ((ifp == NULL) || (ofp == NULL))
  33. >      return (0); 
  34. >
  35. >   while (fgetline(ifp, line, MAX_LINE_LEN) != -1)
  36. >   {
  37. >      /* store the name and value in variables */
  38. >      if (sscanf(line, "%s %s", name, value) != 2)
  39. >      {
  40. >         printf("Bad input from sscanf\n");
  41. >         return (0); 
  42. >      }
  43. >               .
  44. >               .
  45. >               .
  46. >    }
  47. >}
  48.  
  49. After turning this snippet into a valid C translation unit, this is 
  50. what I've got:
  51.  
  52.     ues5:~/Files 88> gcc -c -Wuninitialized -O usaid.c
  53.     usaid.c: In function `formatFile':
  54.     usaid.c:8: warning: `name' might be used uninitialized in this function
  55.     usaid.c:9: warning: `value' might be used uninitialized in this function
  56.  
  57. Does this ring a bell?  If not, read the FAQ.
  58.  
  59. Dan
  60. -- 
  61. Dan Pop
  62. CERN, CN Division
  63. Email: danpop@mail.cern.ch 
  64. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  65.